<template>
    <div>
      <Form :label-width="140">
        <FormItem label="商户名称" required>
          <Input v-model="formData.orgName" placeholder="请输入供应商名称"/>
        </FormItem>
        <FormItem label="微信商户号" required>
          <Input v-model="formData.mchId" placeholder="请输入微信商户号"/>
        </FormItem>
        <FormItem label="企业类型" required>
					<Select class="view-input" placeholder="请选择企业类型" v-model="formData.orgType">
						<Option :value="0">小微商户</Option>
						<Option :value="1">个体商户</Option>
						<Option :value="2">村集体</Option>
						<Option :value="4">供销社</Option>
						<Option :value="6">中小企业</Option>
						<Option :value="9">政府及事业单位</Option>
					</Select>
				</FormItem>
        <FormItem label="统一社会信用代码" required>
          <Input v-model="formData.unionCreditCode" placeholder="请输入统一社会信用代码"/>
        </FormItem>
        <FormItem label="所在地区" required>
          <Cascader class="view-input" v-model="regionVo" :data="regionArray" @on-change="regionSelector" :load-data="loadData"></Cascader>
        </FormItem>
        <FormItem label="法人姓名" required>
          <Input v-model="formData.legalPerson" placeholder="请输入用户姓名"/>
        </FormItem>
        <FormItem label="法人手机号" required>
          <Input v-model="formData.legalMobile" placeholder="请输入法人手机号"/>
        </FormItem>
        <FormItem label="开户行名称" >
          <Input v-model="formData.orgInfo.bankName" placeholder="请输入开户行名称"/>
        </FormItem>
        <FormItem label="银行卡号" >
          <Input v-model="formData.orgInfo.bankAccount" placeholder="请输入银行卡号"/>
        </FormItem>
        <FormItem label="详细地址">
          <Input v-model="formData.addressDetail" placeholder="请输入详细地址"/>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="Submit">提交</Button>
        </FormItem>
      </Form>
  </div>
</template>
<script>
export default {
  name: "CreateVue",
  props: {
    callbank: Function
  },
  data() {
    return {
      regionArray: [],
      regionVo: [],
      formData: {
        orgInfo:{}
      }
    }
  },
  created() {
    
  },
  methods: {
    Init(orgId) {
      this.findOrgInfo(orgId)
      this.regionInit()
    },
    findOrgInfo(orgId) {
      new this.$rest({
				gateway: 'agrobiz',
        service: "agrobiz-uc",
        url: "/v1.0/plus/find/org/info",
				query: {
					equal: orgId
				},
				action: (res)=>{
					if(res.data.code === 20000){
						const data = res.data.data
						this.formData = data
            this.regionVo = [data.provinceCode,data.cityCode,data.countyCode,data.townshipCode]
					} else {
						this.$Message.error({
              content: res.data.msg
            })
					}
				}
			}).get()
    },
    regionInit() {
      new this.$rest({
				gateway: 'agrobiz',
        service: "agrobiz-uc",
        url: "/v1.0/plus/union/region/lazy",
				query: {
					equal: {
            regionId: "0"
          }
				},
				action: (res)=>{
					if(res.data.code === 20000){
						const data = res.data.data
						this.regionArray = data
					} else {
						this.$Message.error({
              content: res.data.msg
            })
					}
				}
			}).get()
    },
    loadData(item, callback) {
			item.loading = true
			new this.$rest({
				gateway: 'agrobiz',
        service: "agrobiz-uc",
        url: "/v1.0/plus/union/region/lazy",
				query: {
					equal: {
            regionId: item.id,
            regionLevel: 4
          }
				},
				action: (res)=>{
					if(res.data.code === 20000){
						const data = res.data.data
						item.children = data
						item.loading = false
            callback()
					} else {
						this.$Message.error({
              content: res.data.msg
            })
					}
				}
			}).get()
		},
    regionSelector(value, data) {
      this.formData.provinceCode = data[0].value
      this.formData.provinceName = data[0].label
      this.formData.cityCode = data[1].value
      this.formData.cityName = data[1].label
      this.formData.countyCode = data[2].value
      this.formData.countyName = data[2].label
      this.formData.townshipCode = data[3].value
      this.formData.townshipName = data[3].label
		},
    Submit() {
      new this.$rest({
          gateway: 'agrobiz',
          service: "agrobiz-uc",
          url: "/v1.0/plus/update/org/info",
          data: {
              pojo: this.formData
          },
          action: (res) => {
            if (res.data.code === 20000) {
              this.$Message.success('修改成功')
              this.callbank()
            } else {
              this.$Message.error(res.data.msg)
            }
          }
      }).post()
    }
  }
}
</script>